package _15_generics._15_4.exercise;

import net.mindview.util.Generator;

import java.util.List;
import java.util.Queue;

/**
 * Overload the fill() method so the arguments
 * and return type are the specific subtypes of
 * Collections:List,Queue and Set.This way,you
 * don't lose the type container. Can you overload
 * to distinguish between List and LinkedList
 */
public class E13_OverloadedFill {
    public static <T> List<T> makeList(List<T> list, Generator<T> gen, int n) {
        for (int i = 0; i < n; i++) {
            list.add(gen.next());
        }
        return list;
    }

    public static <T> Queue<T> makeList(Queue<T> queue,Generator<T> gen, int n) {
        for (int i = 0; i < n; i++) {
            queue.add(gen.next());
        }
        return queue;
    }
}
